home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / MPW Related / Animated Cursors / CursWindTkl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  6.7 KB  |  226 lines  |  [TEXT/MPS ]

  1. /******************************************************************************\
  2. * Header Files
  3. \******************************************************************************/
  4.  
  5. #include <Events.h>
  6. #include <Memory.h>
  7. #include <Windows.h>
  8. #include "AnimCursor.h"
  9. #include "ShowCursor.h"
  10. #include "CursWindTkl.h"
  11. #include "WindowTkl.h"
  12.  
  13.  
  14. /******************************************************************************\
  15. * Constants & Macros
  16. \******************************************************************************/
  17.  
  18. #define cursWindID 128 //Resource ID of Cursor window
  19.  
  20.  
  21. /******************************************************************************\
  22. * Function Prototypes
  23. \******************************************************************************/
  24.  
  25. void ProgressCursor (void);
  26. void BeachBallCursor (void);
  27.  
  28.  
  29. #pragma segment Main
  30. /******************************************************************************\
  31. * CreateCursWind - Create a new Cursor window
  32. *
  33. * CreateCursWind creates a new Cursor window and returns a pointer to it.  The
  34. * window is set to the current port and is centered on the screen.  If there
  35. * isn’t enough memory for a new window, gApplErr is set to memFulErr.  If the
  36. * window’s resource couldn’t be found, gApplErr is set to appDmgErr.  In both
  37. * cases, null is returned.
  38. \******************************************************************************/
  39.  
  40. WindowPtr
  41. CreateCursWind ()
  42.     {
  43.     Ptr           WindStore;  //-> Window record storage
  44.     WindowPtr    CursWind;   //-> New Cursor window
  45.     Point         CentPoint;  //Top-left corner of window to center it
  46.     ControlHandle TheControl; //=> Button controls
  47.  
  48.     WindStore = (Ptr) null;
  49.     CursWind = (WindowPtr) null;
  50.     if ((WindStore = NewPtr ((Size) sizeof (WindowRecord))) == (Ptr) null)
  51.         {
  52.         gApplErr = memFulErr;
  53.         goto Abort;
  54.         }
  55.     if ((CursWind = (WindowPtr) GetNewWindow (cursWindID, WindStore,
  56.             (WindowPtr) -1)) == (WindowPtr) null)
  57.         {
  58.         if (MemError () != noErr)
  59.             gApplErr = memFulErr;
  60.         else
  61.             gApplErr = appDmgErr;
  62.         goto Abort;
  63.         }
  64.     ((WindowPeek) CursWind)->windowKind = cursWindKind;
  65.     SetWindSize ((WindowPtr) CursWind);
  66.     SetPort ((GrafPtr) CursWind);
  67.     CentPoint.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - (CursWind->portRect.
  68.             right - CursWind->portRect.left) + qd.screenBits.bounds.left) >> 1;
  69.     CentPoint.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - (CursWind->portRect.
  70.             bottom - CursWind->portRect.top) + qd.screenBits.bounds.top) / 3;
  71.     MoveWindow ((WindowPtr) CursWind, CentPoint.h, CentPoint.v, true);
  72.     if ((TheControl = GetNewControl (128, (WindowPtr) CursWind)) == (ControlHandle) null)
  73.         {
  74.         gApplErr = appDmgErr;
  75.         goto Abort;
  76.         }
  77.     (**TheControl).contrlRfCon = 0L;
  78.     if ((TheControl = GetNewControl (129, (WindowPtr) CursWind)) == (ControlHandle) null)
  79.         {
  80.         gApplErr = appDmgErr;
  81.         goto Abort;
  82.         }
  83.     (**TheControl).contrlRfCon = 1L;
  84.     ShowWindow ((WindowPtr) CursWind);
  85.     return CursWind;
  86.  
  87. Abort:
  88.     if (CursWind!= (WindowPtr) null)
  89.         CloseWindow ((WindowPtr) CursWind);
  90.     if (WindStore != (Ptr) null)
  91.         DisposPtr (WindStore);
  92.     return (WindowPtr) null;
  93.     }
  94.  
  95.  
  96. #pragma segment Main
  97. /******************************************************************************\
  98. * DrawCursWind - Draw into a Cursor window
  99. *
  100. * DrawCursWind draws into the Cursor window specified by CursWind.
  101. \******************************************************************************/
  102.  
  103. void
  104. DrawCursWind (CursWind)
  105.     WindowPtr CursWind; //-> Cursor window to draw <>
  106.     {
  107.     DrawControls ((WindowPtr) CursWind);
  108.     }
  109.  
  110.  
  111. #pragma segment Main
  112. /******************************************************************************\
  113. * ContentCursWind - Handle a click in the contents of a Cursor window
  114. *
  115. * ContentCursWind handles a click in the content region of the window pointed to
  116. * by CursWind.
  117. \******************************************************************************/
  118.  
  119. void
  120. ContentCursWind (TheEvent, CursWind)
  121.     EventRecord *TheEvent; //-> Event record that recorded the click >>
  122.     WindowPtr  CursWind;  //-> Cursor window to draw <>
  123.     {
  124.     GrafPtr       CurrPort;   //-> Current GrafPort
  125.     Point         ClickPoint; //Coordinate of mouse click in window coords
  126.     ControlHandle TheControl; //=> Clicked control
  127.     short         ThePart;    //Part number of clicked control part
  128.  
  129.     GetPort (&CurrPort);
  130.     SetPort ((GrafPtr) CursWind);
  131.     ClickPoint = TheEvent->where;
  132.     GlobalToLocal (&ClickPoint);
  133.     ThePart = FindControl (ClickPoint, (WindowPtr) CursWind, &TheControl);
  134.     if (ThePart != 0)
  135.         {
  136.         if (TrackControl (TheControl, ClickPoint, (ProcPtr) null))
  137.             if ((**TheControl).contrlRfCon == 0L)
  138.                 ProgressCursor ();
  139.             else if ((**TheControl).contrlRfCon == 1L)
  140.                 BeachBallCursor ();
  141.         }
  142.     SetPort (CurrPort);
  143.     }
  144.  
  145.  
  146. #pragma segment Main
  147. /******************************************************************************\
  148. * ProgressCursor - Show a progress cursor
  149. *
  150. * ProgressCursor shows a progress cursor.  Nothing really happens during this
  151. * time, it’s just wasting it.
  152. \******************************************************************************/
  153.  
  154. static void
  155. ProgressCursor ()
  156.     {
  157.     short       Min;      /* Minimum value of Index */
  158.     short       Max;      /* Maximum value of Index */
  159.     short       Index;    /* Index of values */
  160.     AnimCursHnd AnimCurs; /* => Animated cursor list */
  161.     long        TheCount; /* Stuff for delay */
  162.  
  163.     if (gEnvirons.hasColorQD)
  164.         AnimCurs = GetAnimCurs (1000);
  165.     else
  166.         AnimCurs = GetAnimCurs (150);
  167.     Min = 0;
  168.     Max = 100;
  169.     for (Index = Min; Index <= Max; Index++)
  170.         {
  171.         AnimateProgCurs (AnimCurs, Min, Max, Index);
  172.         Delay (3, &TheCount);
  173.         }
  174.     DisposeAnimCurs (AnimCurs);
  175.     }
  176.  
  177.  
  178. #pragma segment Main
  179. /******************************************************************************\
  180. * BeachBallCursor - Show a BeachBall cursor
  181. *
  182. * BeachBallCursor shows a beachball cursor.  The beachball animates until the
  183. * user clicks the mouse button.
  184. \******************************************************************************/
  185.  
  186. static void
  187. BeachBallCursor ()
  188.     {
  189.     short       Index;
  190.     AnimCursHnd AnimCurs;
  191.     long        TheCount;
  192.     EventRecord TheEvent;
  193.     short       StillGoing;
  194.  
  195.     if (gEnvirons.hasColorQD)
  196.         AnimCurs = GetAnimCurs (2000);
  197.     else
  198.         AnimCurs = GetAnimCurs (128);
  199.     StillGoing = true;
  200.     while (StillGoing)
  201.         {
  202.         if (EventAvail (everyEvent, &TheEvent))
  203.             if (TheEvent.what == mouseDown || TheEvent.what == app4Evt)
  204.                 StillGoing = false;
  205.         AnimateCurs (AnimCurs);
  206.         Delay (3, &TheCount);
  207.         }
  208.     DisposeAnimCurs (AnimCurs);
  209.     }
  210.  
  211.  
  212. #pragma segment Main
  213. /******************************************************************************\
  214. * CloseCursWind - Close a Cursor window
  215. *
  216. * CloseCursWind closes the Cursor window specified by CursWind.
  217. \******************************************************************************/
  218.  
  219. void
  220. CloseCursWind (CursWind)
  221.     WindowPtr CursWind; //-> Cursor window to close <>
  222.     {
  223.     CloseWindow ((WindowPtr) CursWind);
  224.     DisposPtr ((Ptr) CursWind);
  225.     }
  226.